﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WanPiJie.WebSite
{
	public static class BabyExtension
	{
		/// <summary>
		/// 年龄
		/// </summary>
		/// <param name="baby"></param>
		/// <returns></returns>
		public static TimeSpan GetAge(this Baby baby)
		{
			return DateTime.Today - baby.Birthday;
		}

		/// <summary>
		/// 年龄 用月表示，含小数
		/// </summary>
		/// <param name="baby"></param>
		/// <returns></returns>
		public static double GetAgeMonths(this Baby baby)
		{
			return baby.GetAgeDays() / (double)30;
		}

		/// <summary>
		/// 年龄用天表示
		/// </summary>
		/// <param name="baby"></param>
		/// <returns></returns>
		public static int GetAgeDays(this Baby baby)
		{
			return Convert.ToInt32(baby.GetAge().TotalDays);
		}
		
		/// <summary>
		/// 年龄信息
		/// </summary>
		/// <param name="baby"></param>
		/// <returns></returns>
		public static string GetAgeInfo(this Baby baby)
		{
			TimeSpan age = baby.GetAge();
			DateTime temp = new DateTime(age.Ticks);
			int years = temp.Year - 1;
			int months = temp.Month - 1;
			int days = temp.Day;

			if (years == 0)
			{
				return String.Format("{0}个月{1}天", months, days);
			}
			else
			{
				return String.Format("{0}岁{1}个月", years, months);
			}
		}

		public static string GetGenderInfo(this Baby baby)
		{
			if (String.Compare("m", baby.Gender, true) == 0)
			{
				return "男宝宝";
			}
			if (String.Compare("f", baby.Gender, true) == 0)
			{
				return "女宝宝";
			}
			return "";
		}

		public static TimeSpan GetIntervalAfterBirth(this Baby baby, DateTime date)
		{
			return date - baby.Birthday;
		}

		public static string GetIntervalInfoAfterBirth(this Baby baby, DateTime date)
		{
			TimeSpan age = baby.GetIntervalAfterBirth(date);
			DateTime temp = new DateTime(age.Ticks);
			int year = temp.Year - 1;
			int month = temp.Month - 1;
			int day = temp.Day - 1;

			if (year == 0)
			{
				return String.Format("{0}个月{1}天", month, day);
			}
			else
			{
				return String.Format("{0}年{1}个月", year, month);
			}
		}
	}
}